package com.booklove.controller.order;

import com.booklove.context.BaseContext;
import com.booklove.domain.dto.NotesjudgeFormDTO;
import com.booklove.domain.dto.PageDTO;
import com.booklove.domain.query.NotesjudgeQuery;
import com.booklove.domain.vo.NotesjudgeVO;
import com.booklove.result.Result;
import com.booklove.service.order.NotesService;
import com.booklove.service.order.NotesjudgeService;
import com.booklove.domain.po.Notesjudge;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


@Slf4j
@RestController("notesjudgeCLL")
@RequestMapping("/notesjudge")
@RequiredArgsConstructor// 使用基本注解的注入形式，仅仅注入需要的变量
public class NotesjudgeController {

    private final NotesjudgeService notesjudgeService;
    private final NotesService notesService;

    /**
     * 保存新增
     */
//    @PostMapping("/")
//    Result<Notesjudge> saveNotesjudge(@RequestBody NotesjudgeFormDTO notesjudgeFormDTO) {
//        Notes notes=new Notes();
//        BeanUtils.copyProperties(notesjudgeFormDTO,notes);
//        notes.setUserId(notesjudgeFormDTO.getWriterId());
//        notesService.save(notes);
//
//        Notesjudge notesjudge = new Notesjudge();
//        BeanUtils.copyProperties(notesjudgeFormDTO, notesjudge);
//        notesjudge.setNoteId(String.valueOf(notes.getId()));
//
//        notesjudge.setUpdatedTime(LocalDateTime.now());
//        notesjudge.setCreatedTime(LocalDateTime.now());
//        notesjudge.setCreatedBy(BaseContext.getCurrentId().intValue());
//        notesjudge.setUpdatedBy(BaseContext.getCurrentId().intValue());
//
//        notesjudgeService.save(notesjudge);
//        return Result.success(notesjudge);
//    }



    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/id")
    Result<String> deleteNotesjudge(@RequestParam("id") Long id) {
        notesjudgeService.removeById(id);
        return Result.success();
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    NotesjudgeVO getNotesjudge(@PathVariable Long id) {
        NotesjudgeVO notesjudgeVO=new NotesjudgeVO();
        Object notesjudge=notesjudgeService.getById(id);
        BeanUtils.copyProperties(notesjudge,notesjudgeVO);
        return notesjudgeVO;
    }


    /**
     * 编辑数据
     *
     * @param notesjudgeFormDTO 实体
     * @return 编辑结果
     */
    @PutMapping("/")
    Result<String> updateNotesjudge(@RequestBody NotesjudgeFormDTO notesjudgeFormDTO) {
        Notesjudge notesjudge=new Notesjudge();
        BeanUtils.copyProperties(notesjudgeFormDTO,notesjudge);
        notesjudge.setUpdatedTime(LocalDateTime.now());
        notesjudge.setUpdatedBy(BaseContext.getCurrentId().intValue());
        notesjudgeService.updateById(notesjudge);
        return Result.success();
    }


    /**
     * 分页查询
     *
     * @param notesjudgeQuery 筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    PageDTO<NotesjudgeVO> notesjudgesPageQuery(NotesjudgeQuery notesjudgeQuery) {
        return notesjudgeService.queryNotesjudgesPage(notesjudgeQuery);
    }

}

